package com.youxin.cpcenter.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.youxin.busfoundation.bean.ResponseObject;
import com.youxin.busfoundation.bean.classify.RequestCityBean;
import com.youxin.busfoundation.bean.classify.RequestClassifyBean;
import com.youxin.busfoundation.bean.classify.ResponseCityBean;
import com.youxin.busfoundation.bean.classify.ResponseClassifyBean;
import com.youxin.busfoundation.bean.search.RequestSearchType;
import com.youxin.busfoundation.bean.search.ResponseSearchTypes;
import com.youxin.cpcenter.common.dbcache.CacheDataObject;
import com.youxin.cpcenter.service.ClassifyService;
import com.youxin.foundation.utils.ObjectUtils;

/**
 * 分类信息和城市查询
 * @author yingde.cao
 *
 */
@CrossOrigin(origins = {"*"}, maxAge = 60000,methods={RequestMethod.GET,RequestMethod.POST,RequestMethod.OPTIONS})
@RestController
public class ClassifyServiceController extends BaseController{
	@Autowired
	private ClassifyService classifyService;
	
	/**
	 * 行业分类查询
	 * @param request
	 * @param httpServletResponse
	 * @param requestBean
	 * @return
	 */
	//@LogMethod(id="ent.classify",eventContent={})
	@RequestMapping(value = "/api/classify/onelevel", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject classifyLevel(HttpServletRequest request, HttpServletResponse httpServletResponse,
			@RequestBody RequestClassifyBean requestBean) {
		try {		
			ObjectUtils.requestNonNull(requestBean,"参数不能为空,格式为JSON.");
			List<ResponseClassifyBean> result=CacheDataObject.instance().getClassifyBeans(classifyService);
			return new ResponseObject(result);
		} catch (Exception e) {		
			logger.error("/api/sms", e);
			return ResponseObject.systemError(e);
		}
	}
	
	/**
	 * 城市地区
	 * @description 
	 * @param request 请求
	 * @param httpServletResponse 返回
	 * @param requestBean RequestCityBean
	 * @return
	 */
	//@LogMethod(id="ent.citys",eventContent={})
	@RequestMapping(value = "/api/citys", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject listCity(HttpServletRequest request, HttpServletResponse httpServletResponse,
			@RequestBody RequestCityBean requestBean) {
		try {		
			ObjectUtils.requestNonNull(requestBean,"参数不能为空,格式为JSON.");
			List<ResponseCityBean> result=CacheDataObject.instance().getCityBeans(classifyService);
			return new ResponseObject(result);
		} catch (Exception e) {		
			logger.error("/api/sms", e);
			return ResponseObject.systemError(e);
		}
	}
	
	/**
	 * 展示搜索类型,企业规模,注册时间等
	 * @param request
	 * @param httpServletResponse
	 * @param reqeustBean
	 * @return
	 */
	//@LogMethod(id="ent.listtypes",eventContent={})
	@RequestMapping(value = "/api/listtypes", method =RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject listTypes(HttpServletRequest request, HttpServletResponse httpServletResponse,
			@RequestBody RequestSearchType reqeustBean) {
		try {			
			ObjectUtils.requestNonNull(reqeustBean, "参数不能为空");
			ResponseSearchTypes result=ResponseSearchTypes.instance(reqeustBean);
			return new ResponseObject(result);
		} catch (Exception e) {
			logger.error("/searchleads异常", e);
			return ResponseObject.systemError(e);
		}
	}
	
}
